Skip to content

Conversation

@alexey-bataev
Copy link
Member

This reverts commit 04c81a9.

This patch causes massive perf regressions at all opt levels, from O0 to
O3. At O0 with the debug info it creates lots of spills/reloads. At
Higher opt level LoppVectorizer cannot vectorizer the expanded code,
becausde it is not aware of the non-aliasing of the pointers. It also
may increase register pressure.
The pass should include cost modelling, should emit hints for the
vectorizer. Without this, it should be disabled.

Created using spr 1.3.7
@alexey-bataev alexey-bataev requested a review from arsenm December 9, 2025 14:52
@llvmbot llvmbot added backend:AArch64 backend:AMDGPU backend:RISC-V backend:PowerPC backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. llvm:codegen backend:SPIR-V LTO Link time optimization (regular/full LTO or ThinLTO) backend:loongarch llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Dec 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-backend-spir-v
@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-backend-powerpc

Author: Alexey Bataev (alexey-bataev)

Changes

This reverts commit 04c81a9.

This patch causes massive perf regressions at all opt levels, from O0 to
O3. At O0 with the debug info it creates lots of spills/reloads. At
Higher opt level LoppVectorizer cannot vectorizer the expanded code,
becausde it is not aware of the non-aliasing of the pointers. It also
may increase register pressure.
The pass should include cost modelling, should emit hints for the
vectorizer. Without this, it should be disabled.


Patch is 49.92 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/171452.diff

37 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (-6)
  • (modified) llvm/include/llvm/Analysis/RuntimeLibcallInfo.h (+5-17)
  • (modified) llvm/include/llvm/CodeGen/LibcallLoweringInfo.h (-68)
  • (modified) llvm/include/llvm/InitializePasses.h (-1)
  • (modified) llvm/lib/Analysis/RuntimeLibcallInfo.cpp (-16)
  • (modified) llvm/lib/CodeGen/CodeGen.cpp (-1)
  • (modified) llvm/lib/CodeGen/ExpandFp.cpp (+8-32)
  • (modified) llvm/lib/CodeGen/LibcallLoweringInfo.cpp (-42)
  • (modified) llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp (+17-36)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (-6)
  • (modified) llvm/lib/Passes/PassRegistry.def (-1)
  • (modified) llvm/test/CodeGen/AArch64/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/AArch64/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/AMDGPU/llc-pipeline.ll (-10)
  • (modified) llvm/test/CodeGen/LoongArch/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/LoongArch/opt-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/PowerPC/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/PowerPC/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/RISCV/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/RISCV/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/SPIRV/llc-pipeline.ll (-4)
  • (modified) llvm/test/CodeGen/X86/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/X86/opt-pipeline.ll (-2)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/frem-inf.ll (+2-2)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/frem.ll (+1-1)
  • (removed) llvm/test/Transforms/ExpandFp/AMDGPU/missing-analysis.ll (-6)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/pass-parameters.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-fptosi129.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-fptoui129.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-si129tofp.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-ui129tofp.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-optnone.ll (+1-1)
  • (modified) llvm/tools/llc/NewPMDriver.cpp (-12)
  • (modified) llvm/tools/llc/llc.cpp (-5)
  • (modified) llvm/tools/opt/NewPMDriver.cpp (+6-17)
  • (modified) llvm/tools/opt/NewPMDriver.h (+7-3)
  • (modified) llvm/tools/opt/optdriver.cpp (+7-12)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 126005a5d93c2..df716e5bce23f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -19,7 +19,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Analysis/GlobalsModRef.h"
-#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -656,11 +655,6 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
       llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
 
-  const llvm::TargetOptions &Options = TM->Options;
-  CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
-      TargetTriple, Options.ExceptionModel, Options.FloatABIType,
-      Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
-
   // Normal mode, emit a .s or .o file by running the code generator. Note,
   // this also adds codegenerator level optimization passes.
   CodeGenFileType CGFT = getCodeGenFileType(Action);
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 609568ebc21a8..79737795e8291 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -22,12 +22,7 @@ class LLVM_ABI RuntimeLibraryAnalysis
   RuntimeLibraryAnalysis() = default;
   RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&BaselineInfoImpl)
       : LibcallsInfo(std::move(BaselineInfoImpl)) {}
-  RuntimeLibraryAnalysis(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  explicit RuntimeLibraryAnalysis(const Triple &T) : LibcallsInfo(T) {}
 
   RTLIB::RuntimeLibcallsInfo run(const Module &M, ModuleAnalysisManager &);
 
@@ -45,19 +40,12 @@ class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
 public:
   static char ID;
   RuntimeLibraryInfoWrapper();
-  RuntimeLibraryInfoWrapper(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  explicit RuntimeLibraryInfoWrapper(const Triple &T);
+  explicit RuntimeLibraryInfoWrapper(const RTLIB::RuntimeLibcallsInfo &RTLCI);
 
   const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) {
-    if (!RTLCI) {
-      ModuleAnalysisManager DummyMAM;
-      RTLCI = RTLA.run(M, DummyMAM);
-    }
-
+    ModuleAnalysisManager DummyMAM;
+    RTLCI = RTLA.run(M, DummyMAM);
     return *RTLCI;
   }
 
diff --git a/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h b/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
index 3e0137710e8eb..8624fd2403a12 100644
--- a/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
+++ b/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
@@ -9,16 +9,12 @@
 #ifndef LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
 #define LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
 
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/IR/RuntimeLibcalls.h"
-#include "llvm/Pass.h"
 
 namespace llvm {
 
 class TargetSubtargetInfo;
-class TargetMachine;
 
-/// Tracks which library functions to use for a particular subtarget.
 class LibcallLoweringInfo {
 private:
   const RTLIB::RuntimeLibcallsInfo &RTLCI;
@@ -77,70 +73,6 @@ class LibcallLoweringInfo {
   }
 };
 
-/// Record a mapping from subtarget to LibcallLoweringInfo.
-class LibcallLoweringModuleAnalysisResult {
-private:
-  using LibcallLoweringMap =
-      DenseMap<const TargetSubtargetInfo *, LibcallLoweringInfo>;
-  mutable LibcallLoweringMap LoweringMap;
-  const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr;
-
-public:
-  LibcallLoweringModuleAnalysisResult() = default;
-  LibcallLoweringModuleAnalysisResult(RTLIB::RuntimeLibcallsInfo &RTLCI)
-      : RTLCI(&RTLCI) {}
-
-  void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; }
-
-  void clear() {
-    RTLCI = nullptr;
-    LoweringMap.clear();
-  }
-
-  LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &,
-                           ModuleAnalysisManager::Invalidator &);
-
-  const LibcallLoweringInfo &
-  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
-    return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second;
-  }
-};
-
-class LibcallLoweringModuleAnalysis
-    : public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> {
-private:
-  friend AnalysisInfoMixin<LibcallLoweringModuleAnalysis>;
-  static AnalysisKey Key;
-
-  LibcallLoweringModuleAnalysisResult LibcallLoweringMap;
-
-public:
-  using Result = LibcallLoweringModuleAnalysisResult;
-
-  LLVM_ABI Result run(Module &M, ModuleAnalysisManager &);
-};
-
-class LLVM_ABI LibcallLoweringInfoWrapper : public ImmutablePass {
-  LibcallLoweringModuleAnalysisResult Result;
-
-public:
-  static char ID;
-  LibcallLoweringInfoWrapper();
-
-  const LibcallLoweringInfo &
-  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
-    return Result.getLibcallLowering(Subtarget);
-  }
-
-  const LibcallLoweringModuleAnalysisResult &getResult() const {
-    return Result;
-  }
-
-  bool doInitialization(Module &M) override;
-  void getAnalysisUsage(AnalysisUsage &AU) const override;
-  void releaseMemory() override;
-};
-
 } // end namespace llvm
 
 #endif // LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index a5491e68bbe52..18732caf78966 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -134,7 +134,6 @@ LLVM_ABI void initializeGlobalMergeFuncPassWrapperPass(PassRegistry &);
 LLVM_ABI void initializeGlobalMergePass(PassRegistry &);
 LLVM_ABI void initializeGlobalsAAWrapperPassPass(PassRegistry &);
 LLVM_ABI void initializeHardwareLoopsLegacyPass(PassRegistry &);
-LLVM_ABI void initializeLibcallLoweringInfoWrapperPass(PassRegistry &);
 LLVM_ABI void initializeMIRProfileLoaderPassPass(PassRegistry &);
 LLVM_ABI void initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &);
 LLVM_ABI void initializeIRTranslatorPass(PassRegistry &);
diff --git a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
index 1c5a1cc75b7bd..9ea789a4ee45a 100644
--- a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
+++ b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
@@ -13,15 +13,6 @@ using namespace llvm;
 
 AnalysisKey RuntimeLibraryAnalysis::Key;
 
-RuntimeLibraryAnalysis::RuntimeLibraryAnalysis(const Triple &TT,
-                                               ExceptionHandling ExceptionModel,
-                                               FloatABI::ABIType FloatABI,
-                                               EABI EABIVersion,
-                                               StringRef ABIName,
-                                               VectorLibrary VecLib)
-    : LibcallsInfo(std::in_place, TT, ExceptionModel, FloatABI, EABIVersion,
-                   ABIName, VecLib) {}
-
 RTLIB::RuntimeLibcallsInfo
 RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
   if (!LibcallsInfo)
@@ -35,13 +26,6 @@ INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
 RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper()
     : ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {}
 
-RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(
-    const Triple &TT, ExceptionHandling ExceptionModel,
-    FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName,
-    VectorLibrary VecLib)
-    : ImmutablePass(ID), RTLCI(std::in_place, TT, ExceptionModel, FloatABI,
-                               EABIVersion, ABIName, VecLib) {}
-
 char RuntimeLibraryInfoWrapper::ID = 0;
 
 ModulePass *llvm::createRuntimeLibraryInfoWrapperPass() {
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index fe293c63fa762..9795a0b707fd3 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -57,7 +57,6 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeInterleavedLoadCombinePass(Registry);
   initializeInterleavedAccessPass(Registry);
   initializeJMCInstrumenterPass(Registry);
-  initializeLibcallLoweringInfoWrapperPass(Registry);
   initializeLiveDebugValuesLegacyPass(Registry);
   initializeLiveDebugVariablesWrapperLegacyPass(Registry);
   initializeLiveIntervalsWrapperPassPass(Registry);
diff --git a/llvm/lib/CodeGen/ExpandFp.cpp b/llvm/lib/CodeGen/ExpandFp.cpp
index 13ed4846d2bf7..f44eb227133ae 100644
--- a/llvm/lib/CodeGen/ExpandFp.cpp
+++ b/llvm/lib/CodeGen/ExpandFp.cpp
@@ -975,12 +975,11 @@ static RTLIB::Libcall fremToLibcall(Type *Ty) {
 /* Return true if, according to \p LibInfo, the target either directly
    supports the frem instruction for the \p Ty, has a custom lowering,
    or uses a libcall. */
-static bool targetSupportsFrem(const TargetLowering &TLI,
-                               const LibcallLoweringInfo &Libcalls, Type *Ty) {
+static bool targetSupportsFrem(const TargetLowering &TLI, Type *Ty) {
   if (!TLI.isOperationExpand(ISD::FREM, EVT::getEVT(Ty)))
     return true;
 
-  return Libcalls.getLibcallName(fremToLibcall(Ty->getScalarType()));
+  return TLI.getLibcallName(fremToLibcall(Ty->getScalarType()));
 }
 
 static void addToWorklist(Instruction &I,
@@ -992,7 +991,7 @@ static void addToWorklist(Instruction &I,
 }
 
 static bool runImpl(Function &F, const TargetLowering &TLI,
-                    const LibcallLoweringInfo &Libcalls, AssumptionCache *AC) {
+                    AssumptionCache *AC) {
   SmallVector<Instruction *, 4> Worklist;
 
   unsigned MaxLegalFpConvertBitWidth =
@@ -1011,7 +1010,7 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
 
     switch (I.getOpcode()) {
     case Instruction::FRem:
-      return !targetSupportsFrem(TLI, Libcalls, Ty) &&
+      return !targetSupportsFrem(TLI, Ty) &&
              FRemExpander::canExpandType(Ty->getScalarType());
 
     case Instruction::FPToUI:
@@ -1091,27 +1090,20 @@ class ExpandFpLegacyPass : public FunctionPass {
 
   bool runOnFunction(Function &F) override {
     auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
-    const TargetSubtargetInfo *Subtarget = TM->getSubtargetImpl(F);
-    auto *TLI = Subtarget->getTargetLowering();
+    auto *TLI = TM->getSubtargetImpl(F)->getTargetLowering();
     AssumptionCache *AC = nullptr;
 
-    const LibcallLoweringInfo &Libcalls =
-        getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering(
-            *Subtarget);
-
     if (OptLevel != CodeGenOptLevel::None && !F.hasOptNone())
       AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
-    return runImpl(F, *TLI, Libcalls, AC);
+    return runImpl(F, *TLI, AC);
   }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
-    AU.addRequired<LibcallLoweringInfoWrapper>();
     AU.addRequired<TargetPassConfig>();
     if (OptLevel != CodeGenOptLevel::None)
       AU.addRequired<AssumptionCacheTracker>();
     AU.addPreserved<AAResultsWrapperPass>();
     AU.addPreserved<GlobalsAAWrapperPass>();
-    AU.addRequired<LibcallLoweringInfoWrapper>();
   }
 };
 } // namespace
@@ -1134,29 +1126,13 @@ PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) {
   AssumptionCache *AC = nullptr;
   if (OptLevel != CodeGenOptLevel::None)
     AC = &FAM.getResult<AssumptionAnalysis>(F);
-
-  auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
-
-  const LibcallLoweringModuleAnalysisResult *LibcallLowering =
-      MAMProxy.getCachedResult<LibcallLoweringModuleAnalysis>(*F.getParent());
-
-  if (!LibcallLowering) {
-    F.getContext().emitError("'" + LibcallLoweringModuleAnalysis::name() +
-                             "' analysis required");
-    return PreservedAnalyses::all();
-  }
-
-  const LibcallLoweringInfo &Libcalls =
-      LibcallLowering->getLibcallLowering(*STI);
-
-  return runImpl(F, TLI, Libcalls, AC) ? PreservedAnalyses::none()
-                                       : PreservedAnalyses::all();
+  return runImpl(F, TLI, AC) ? PreservedAnalyses::none()
+                             : PreservedAnalyses::all();
 }
 
 char ExpandFpLegacyPass::ID = 0;
 INITIALIZE_PASS_BEGIN(ExpandFpLegacyPass, "expand-fp",
                       "Expand certain fp instructions", false, false)
-INITIALIZE_PASS_DEPENDENCY(LibcallLoweringInfoWrapper)
 INITIALIZE_PASS_END(ExpandFpLegacyPass, "expand-fp", "Expand fp", false, false)
 
 FunctionPass *llvm::createExpandFpPass(CodeGenOptLevel OptLevel) {
diff --git a/llvm/lib/CodeGen/LibcallLoweringInfo.cpp b/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
index 0d54fac2422e2..6f3607e8db824 100644
--- a/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
@@ -7,10 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/LibcallLoweringInfo.h"
-#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
-#include "llvm/InitializePasses.h"
-#include "llvm/Target/TargetMachine.h"
 
 using namespace llvm;
 
@@ -31,42 +28,3 @@ LibcallLoweringInfo::LibcallLoweringInfo(
 
   Subtarget.initLibcallLoweringInfo(*this);
 }
-
-AnalysisKey LibcallLoweringModuleAnalysis::Key;
-
-bool LibcallLoweringModuleAnalysisResult::invalidate(
-    Module &, const PreservedAnalyses &PA,
-    ModuleAnalysisManager::Invalidator &) {
-  // Passes that change the runtime libcall set must explicitly invalidate this
-  // pass.
-  auto PAC = PA.getChecker<LibcallLoweringModuleAnalysis>();
-  return !PAC.preservedWhenStateless();
-}
-
-LibcallLoweringModuleAnalysisResult
-LibcallLoweringModuleAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
-  LibcallLoweringMap.init(&MAM.getResult<RuntimeLibraryAnalysis>(M));
-  return LibcallLoweringMap;
-}
-
-INITIALIZE_PASS_BEGIN(LibcallLoweringInfoWrapper, "libcall-lowering-info",
-                      "Library Function Lowering Analysis", false, true)
-INITIALIZE_PASS_DEPENDENCY(RuntimeLibraryInfoWrapper)
-INITIALIZE_PASS_END(LibcallLoweringInfoWrapper, "libcall-lowering-info",
-                    "Library Function Lowering Analysis", false, true)
-
-char LibcallLoweringInfoWrapper::ID = 0;
-
-LibcallLoweringInfoWrapper::LibcallLoweringInfoWrapper() : ImmutablePass(ID) {}
-
-bool LibcallLoweringInfoWrapper::doInitialization(Module &M) {
-  Result.init(&getAnalysis<RuntimeLibraryInfoWrapper>().getRTLCI(M));
-  return false;
-}
-
-void LibcallLoweringInfoWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
-  AU.addRequired<RuntimeLibraryInfoWrapper>();
-  AU.setPreservesAll();
-}
-
-void LibcallLoweringInfoWrapper::releaseMemory() { Result.clear(); }
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 97da9abab0b7b..382d84a2ef030 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -17,7 +17,6 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/ExpandVectorPredication.h"
-#include "llvm/CodeGen/LibcallLoweringInfo.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/TargetLowering.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
@@ -54,7 +53,6 @@ namespace {
 
 struct PreISelIntrinsicLowering {
   const TargetMachine *TM;
-  const LibcallLoweringModuleAnalysisResult &ModuleLibcalls;
   const function_ref<TargetTransformInfo &(Function &)> LookupTTI;
   const function_ref<TargetLibraryInfo &(Function &)> LookupTLI;
 
@@ -65,13 +63,11 @@ struct PreISelIntrinsicLowering {
 
   explicit PreISelIntrinsicLowering(
       const TargetMachine *TM_,
-      const LibcallLoweringModuleAnalysisResult &ModuleLibcalls_,
       function_ref<TargetTransformInfo &(Function &)> LookupTTI_,
       function_ref<TargetLibraryInfo &(Function &)> LookupTLI_,
       bool UseMemIntrinsicLibFunc_ = true)
-      : TM(TM_), ModuleLibcalls(ModuleLibcalls_), LookupTTI(LookupTTI_),
-        LookupTLI(LookupTLI_), UseMemIntrinsicLibFunc(UseMemIntrinsicLibFunc_) {
-  }
+      : TM(TM_), LookupTTI(LookupTTI_), LookupTLI(LookupTLI_),
+        UseMemIntrinsicLibFunc(UseMemIntrinsicLibFunc_) {}
 
   static bool shouldExpandMemIntrinsicWithSize(Value *Size,
                                                const TargetTransformInfo &TTI);
@@ -236,26 +232,21 @@ bool PreISelIntrinsicLowering::shouldExpandMemIntrinsicWithSize(
   return SizeVal > Threshold || Threshold == 0;
 }
 
-static bool
-canEmitLibcall(const LibcallLoweringModuleAnalysisResult &ModuleLowering,
-               const TargetMachine *TM, Function *F, RTLIB::Libcall LC) {
+static bool canEmitLibcall(const TargetMachine *TM, Function *F,
+                           RTLIB::Libcall LC) {
   // TODO: Should this consider the address space of the memcpy?
   if (!TM)
     return true;
-  const LibcallLoweringInfo &Lowering =
-      ModuleLowering.getLibcallLowering(*TM->getSubtargetImpl(*F));
-  return Lowering.getLibcallImpl(LC) != RTLIB::Unsupported;
+  const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getLibcallName(LC) != nullptr;
 }
 
-static bool
-canEmitMemcpy(const LibcallLoweringModuleAnalysisResult &ModuleLowering,
-              const TargetMachine *TM, Function *F) {
+static bool canEmitMemcpy(const TargetMachine *TM, Function *F) {
   // TODO: Should this consider the address space of the memcpy?
   if (!TM)
     return true;
-  const LibcallLoweringInfo &Lowering =
-      ModuleLowering.getLibcallLowering(*TM->getSubtargetImpl(*F));
-  return Lowering.getMemcpyImpl() != RTLIB::Unsupported;
+  const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getMemcpyImpl() != RTLIB::Unsupported;
 }
 
 // Return a value appropriate for use with the memset_pattern16 libcall, if
@@ -328,8 +319,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       Function *ParentFunc = Memcpy->getFunction();
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memcpy->getLength(), TTI)) {
-        if (UseMemIntrinsicLibFunc &&
-            canEmitMemcpy(ModuleLibcalls, TM, ParentFunc))
+        if (UseMemIntrinsicLibFunc && canEmitMemcpy(TM, ParentFunc))
           break;
 
         // TODO: For optsize, emit the loop into a separate function
@@ -361,7 +351,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memmove->getLength(), TTI)) {
         if (UseMemIntrinsicLibFunc &&
-            canEmitLibcall(ModuleLibcalls, TM, ParentFunc, RTLIB::MEMMOVE))
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMMOVE))
           break;
 
         if (expandMemMoveAsLoop(Memmove, TTI)) {
@@ -378,7 +368,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memset->getLength(), TTI)) {
         if (UseMemIntrinsicLibFunc &&
-            canEmitLibcall(ModuleLibcalls, TM, ParentFunc, RTLIB::MEMSET))
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMSET))
           break;
 
         expandMemSetAsLoop(Memset);
@@ -772,14 +762,10 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass {
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<TargetTransformInfoWrapperPass>();
     AU.addRequired<TargetLibraryInfoWrapperPass>();
-    AU.addRequired<LibcallLoweringInfoWrapper>();
     AU.addRequired<TargetPassConfig>();
   }
 
   bool runOnModule(Module &M) override {
-    const LibcallLoweringModuleAnalysisResult &ModuleLibcalls =
-        getAnalysis<LibcallLoweringInfoWrapper>().getResult();
-
     auto LookupTTI = [this](Function &F) -> TargetTransformInfo & {
       return this->getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
     };
@@ -788,7 +774,7 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass {
     };
 
     const a...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Alexey Bataev (alexey-bataev)

Changes

This reverts commit 04c81a9.

This patch causes massive perf regressions at all opt levels, from O0 to
O3. At O0 with the debug info it creates lots of spills/reloads. At
Higher opt level LoppVectorizer cannot vectorizer the expanded code,
becausde it is not aware of the non-aliasing of the pointers. It also
may increase register pressure.
The pass should include cost modelling, should emit hints for the
vectorizer. Without this, it should be disabled.


Patch is 49.92 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/171452.diff

37 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (-6)
  • (modified) llvm/include/llvm/Analysis/RuntimeLibcallInfo.h (+5-17)
  • (modified) llvm/include/llvm/CodeGen/LibcallLoweringInfo.h (-68)
  • (modified) llvm/include/llvm/InitializePasses.h (-1)
  • (modified) llvm/lib/Analysis/RuntimeLibcallInfo.cpp (-16)
  • (modified) llvm/lib/CodeGen/CodeGen.cpp (-1)
  • (modified) llvm/lib/CodeGen/ExpandFp.cpp (+8-32)
  • (modified) llvm/lib/CodeGen/LibcallLoweringInfo.cpp (-42)
  • (modified) llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp (+17-36)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (-6)
  • (modified) llvm/lib/Passes/PassRegistry.def (-1)
  • (modified) llvm/test/CodeGen/AArch64/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/AArch64/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/AMDGPU/llc-pipeline.ll (-10)
  • (modified) llvm/test/CodeGen/LoongArch/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/LoongArch/opt-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/PowerPC/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/PowerPC/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/RISCV/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/RISCV/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/SPIRV/llc-pipeline.ll (-4)
  • (modified) llvm/test/CodeGen/X86/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/X86/opt-pipeline.ll (-2)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/frem-inf.ll (+2-2)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/frem.ll (+1-1)
  • (removed) llvm/test/Transforms/ExpandFp/AMDGPU/missing-analysis.ll (-6)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/pass-parameters.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-fptosi129.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-fptoui129.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-si129tofp.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-ui129tofp.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-optnone.ll (+1-1)
  • (modified) llvm/tools/llc/NewPMDriver.cpp (-12)
  • (modified) llvm/tools/llc/llc.cpp (-5)
  • (modified) llvm/tools/opt/NewPMDriver.cpp (+6-17)
  • (modified) llvm/tools/opt/NewPMDriver.h (+7-3)
  • (modified) llvm/tools/opt/optdriver.cpp (+7-12)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 126005a5d93c2..df716e5bce23f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -19,7 +19,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Analysis/GlobalsModRef.h"
-#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -656,11 +655,6 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
       llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
 
-  const llvm::TargetOptions &Options = TM->Options;
-  CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
-      TargetTriple, Options.ExceptionModel, Options.FloatABIType,
-      Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
-
   // Normal mode, emit a .s or .o file by running the code generator. Note,
   // this also adds codegenerator level optimization passes.
   CodeGenFileType CGFT = getCodeGenFileType(Action);
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 609568ebc21a8..79737795e8291 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -22,12 +22,7 @@ class LLVM_ABI RuntimeLibraryAnalysis
   RuntimeLibraryAnalysis() = default;
   RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&BaselineInfoImpl)
       : LibcallsInfo(std::move(BaselineInfoImpl)) {}
-  RuntimeLibraryAnalysis(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  explicit RuntimeLibraryAnalysis(const Triple &T) : LibcallsInfo(T) {}
 
   RTLIB::RuntimeLibcallsInfo run(const Module &M, ModuleAnalysisManager &);
 
@@ -45,19 +40,12 @@ class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
 public:
   static char ID;
   RuntimeLibraryInfoWrapper();
-  RuntimeLibraryInfoWrapper(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  explicit RuntimeLibraryInfoWrapper(const Triple &T);
+  explicit RuntimeLibraryInfoWrapper(const RTLIB::RuntimeLibcallsInfo &RTLCI);
 
   const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) {
-    if (!RTLCI) {
-      ModuleAnalysisManager DummyMAM;
-      RTLCI = RTLA.run(M, DummyMAM);
-    }
-
+    ModuleAnalysisManager DummyMAM;
+    RTLCI = RTLA.run(M, DummyMAM);
     return *RTLCI;
   }
 
diff --git a/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h b/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
index 3e0137710e8eb..8624fd2403a12 100644
--- a/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
+++ b/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
@@ -9,16 +9,12 @@
 #ifndef LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
 #define LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
 
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/IR/RuntimeLibcalls.h"
-#include "llvm/Pass.h"
 
 namespace llvm {
 
 class TargetSubtargetInfo;
-class TargetMachine;
 
-/// Tracks which library functions to use for a particular subtarget.
 class LibcallLoweringInfo {
 private:
   const RTLIB::RuntimeLibcallsInfo &RTLCI;
@@ -77,70 +73,6 @@ class LibcallLoweringInfo {
   }
 };
 
-/// Record a mapping from subtarget to LibcallLoweringInfo.
-class LibcallLoweringModuleAnalysisResult {
-private:
-  using LibcallLoweringMap =
-      DenseMap<const TargetSubtargetInfo *, LibcallLoweringInfo>;
-  mutable LibcallLoweringMap LoweringMap;
-  const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr;
-
-public:
-  LibcallLoweringModuleAnalysisResult() = default;
-  LibcallLoweringModuleAnalysisResult(RTLIB::RuntimeLibcallsInfo &RTLCI)
-      : RTLCI(&RTLCI) {}
-
-  void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; }
-
-  void clear() {
-    RTLCI = nullptr;
-    LoweringMap.clear();
-  }
-
-  LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &,
-                           ModuleAnalysisManager::Invalidator &);
-
-  const LibcallLoweringInfo &
-  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
-    return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second;
-  }
-};
-
-class LibcallLoweringModuleAnalysis
-    : public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> {
-private:
-  friend AnalysisInfoMixin<LibcallLoweringModuleAnalysis>;
-  static AnalysisKey Key;
-
-  LibcallLoweringModuleAnalysisResult LibcallLoweringMap;
-
-public:
-  using Result = LibcallLoweringModuleAnalysisResult;
-
-  LLVM_ABI Result run(Module &M, ModuleAnalysisManager &);
-};
-
-class LLVM_ABI LibcallLoweringInfoWrapper : public ImmutablePass {
-  LibcallLoweringModuleAnalysisResult Result;
-
-public:
-  static char ID;
-  LibcallLoweringInfoWrapper();
-
-  const LibcallLoweringInfo &
-  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
-    return Result.getLibcallLowering(Subtarget);
-  }
-
-  const LibcallLoweringModuleAnalysisResult &getResult() const {
-    return Result;
-  }
-
-  bool doInitialization(Module &M) override;
-  void getAnalysisUsage(AnalysisUsage &AU) const override;
-  void releaseMemory() override;
-};
-
 } // end namespace llvm
 
 #endif // LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index a5491e68bbe52..18732caf78966 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -134,7 +134,6 @@ LLVM_ABI void initializeGlobalMergeFuncPassWrapperPass(PassRegistry &);
 LLVM_ABI void initializeGlobalMergePass(PassRegistry &);
 LLVM_ABI void initializeGlobalsAAWrapperPassPass(PassRegistry &);
 LLVM_ABI void initializeHardwareLoopsLegacyPass(PassRegistry &);
-LLVM_ABI void initializeLibcallLoweringInfoWrapperPass(PassRegistry &);
 LLVM_ABI void initializeMIRProfileLoaderPassPass(PassRegistry &);
 LLVM_ABI void initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &);
 LLVM_ABI void initializeIRTranslatorPass(PassRegistry &);
diff --git a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
index 1c5a1cc75b7bd..9ea789a4ee45a 100644
--- a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
+++ b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
@@ -13,15 +13,6 @@ using namespace llvm;
 
 AnalysisKey RuntimeLibraryAnalysis::Key;
 
-RuntimeLibraryAnalysis::RuntimeLibraryAnalysis(const Triple &TT,
-                                               ExceptionHandling ExceptionModel,
-                                               FloatABI::ABIType FloatABI,
-                                               EABI EABIVersion,
-                                               StringRef ABIName,
-                                               VectorLibrary VecLib)
-    : LibcallsInfo(std::in_place, TT, ExceptionModel, FloatABI, EABIVersion,
-                   ABIName, VecLib) {}
-
 RTLIB::RuntimeLibcallsInfo
 RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
   if (!LibcallsInfo)
@@ -35,13 +26,6 @@ INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
 RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper()
     : ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {}
 
-RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(
-    const Triple &TT, ExceptionHandling ExceptionModel,
-    FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName,
-    VectorLibrary VecLib)
-    : ImmutablePass(ID), RTLCI(std::in_place, TT, ExceptionModel, FloatABI,
-                               EABIVersion, ABIName, VecLib) {}
-
 char RuntimeLibraryInfoWrapper::ID = 0;
 
 ModulePass *llvm::createRuntimeLibraryInfoWrapperPass() {
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index fe293c63fa762..9795a0b707fd3 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -57,7 +57,6 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeInterleavedLoadCombinePass(Registry);
   initializeInterleavedAccessPass(Registry);
   initializeJMCInstrumenterPass(Registry);
-  initializeLibcallLoweringInfoWrapperPass(Registry);
   initializeLiveDebugValuesLegacyPass(Registry);
   initializeLiveDebugVariablesWrapperLegacyPass(Registry);
   initializeLiveIntervalsWrapperPassPass(Registry);
diff --git a/llvm/lib/CodeGen/ExpandFp.cpp b/llvm/lib/CodeGen/ExpandFp.cpp
index 13ed4846d2bf7..f44eb227133ae 100644
--- a/llvm/lib/CodeGen/ExpandFp.cpp
+++ b/llvm/lib/CodeGen/ExpandFp.cpp
@@ -975,12 +975,11 @@ static RTLIB::Libcall fremToLibcall(Type *Ty) {
 /* Return true if, according to \p LibInfo, the target either directly
    supports the frem instruction for the \p Ty, has a custom lowering,
    or uses a libcall. */
-static bool targetSupportsFrem(const TargetLowering &TLI,
-                               const LibcallLoweringInfo &Libcalls, Type *Ty) {
+static bool targetSupportsFrem(const TargetLowering &TLI, Type *Ty) {
   if (!TLI.isOperationExpand(ISD::FREM, EVT::getEVT(Ty)))
     return true;
 
-  return Libcalls.getLibcallName(fremToLibcall(Ty->getScalarType()));
+  return TLI.getLibcallName(fremToLibcall(Ty->getScalarType()));
 }
 
 static void addToWorklist(Instruction &I,
@@ -992,7 +991,7 @@ static void addToWorklist(Instruction &I,
 }
 
 static bool runImpl(Function &F, const TargetLowering &TLI,
-                    const LibcallLoweringInfo &Libcalls, AssumptionCache *AC) {
+                    AssumptionCache *AC) {
   SmallVector<Instruction *, 4> Worklist;
 
   unsigned MaxLegalFpConvertBitWidth =
@@ -1011,7 +1010,7 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
 
     switch (I.getOpcode()) {
     case Instruction::FRem:
-      return !targetSupportsFrem(TLI, Libcalls, Ty) &&
+      return !targetSupportsFrem(TLI, Ty) &&
              FRemExpander::canExpandType(Ty->getScalarType());
 
     case Instruction::FPToUI:
@@ -1091,27 +1090,20 @@ class ExpandFpLegacyPass : public FunctionPass {
 
   bool runOnFunction(Function &F) override {
     auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
-    const TargetSubtargetInfo *Subtarget = TM->getSubtargetImpl(F);
-    auto *TLI = Subtarget->getTargetLowering();
+    auto *TLI = TM->getSubtargetImpl(F)->getTargetLowering();
     AssumptionCache *AC = nullptr;
 
-    const LibcallLoweringInfo &Libcalls =
-        getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering(
-            *Subtarget);
-
     if (OptLevel != CodeGenOptLevel::None && !F.hasOptNone())
       AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
-    return runImpl(F, *TLI, Libcalls, AC);
+    return runImpl(F, *TLI, AC);
   }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
-    AU.addRequired<LibcallLoweringInfoWrapper>();
     AU.addRequired<TargetPassConfig>();
     if (OptLevel != CodeGenOptLevel::None)
       AU.addRequired<AssumptionCacheTracker>();
     AU.addPreserved<AAResultsWrapperPass>();
     AU.addPreserved<GlobalsAAWrapperPass>();
-    AU.addRequired<LibcallLoweringInfoWrapper>();
   }
 };
 } // namespace
@@ -1134,29 +1126,13 @@ PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) {
   AssumptionCache *AC = nullptr;
   if (OptLevel != CodeGenOptLevel::None)
     AC = &FAM.getResult<AssumptionAnalysis>(F);
-
-  auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
-
-  const LibcallLoweringModuleAnalysisResult *LibcallLowering =
-      MAMProxy.getCachedResult<LibcallLoweringModuleAnalysis>(*F.getParent());
-
-  if (!LibcallLowering) {
-    F.getContext().emitError("'" + LibcallLoweringModuleAnalysis::name() +
-                             "' analysis required");
-    return PreservedAnalyses::all();
-  }
-
-  const LibcallLoweringInfo &Libcalls =
-      LibcallLowering->getLibcallLowering(*STI);
-
-  return runImpl(F, TLI, Libcalls, AC) ? PreservedAnalyses::none()
-                                       : PreservedAnalyses::all();
+  return runImpl(F, TLI, AC) ? PreservedAnalyses::none()
+                             : PreservedAnalyses::all();
 }
 
 char ExpandFpLegacyPass::ID = 0;
 INITIALIZE_PASS_BEGIN(ExpandFpLegacyPass, "expand-fp",
                       "Expand certain fp instructions", false, false)
-INITIALIZE_PASS_DEPENDENCY(LibcallLoweringInfoWrapper)
 INITIALIZE_PASS_END(ExpandFpLegacyPass, "expand-fp", "Expand fp", false, false)
 
 FunctionPass *llvm::createExpandFpPass(CodeGenOptLevel OptLevel) {
diff --git a/llvm/lib/CodeGen/LibcallLoweringInfo.cpp b/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
index 0d54fac2422e2..6f3607e8db824 100644
--- a/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
@@ -7,10 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/LibcallLoweringInfo.h"
-#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
-#include "llvm/InitializePasses.h"
-#include "llvm/Target/TargetMachine.h"
 
 using namespace llvm;
 
@@ -31,42 +28,3 @@ LibcallLoweringInfo::LibcallLoweringInfo(
 
   Subtarget.initLibcallLoweringInfo(*this);
 }
-
-AnalysisKey LibcallLoweringModuleAnalysis::Key;
-
-bool LibcallLoweringModuleAnalysisResult::invalidate(
-    Module &, const PreservedAnalyses &PA,
-    ModuleAnalysisManager::Invalidator &) {
-  // Passes that change the runtime libcall set must explicitly invalidate this
-  // pass.
-  auto PAC = PA.getChecker<LibcallLoweringModuleAnalysis>();
-  return !PAC.preservedWhenStateless();
-}
-
-LibcallLoweringModuleAnalysisResult
-LibcallLoweringModuleAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
-  LibcallLoweringMap.init(&MAM.getResult<RuntimeLibraryAnalysis>(M));
-  return LibcallLoweringMap;
-}
-
-INITIALIZE_PASS_BEGIN(LibcallLoweringInfoWrapper, "libcall-lowering-info",
-                      "Library Function Lowering Analysis", false, true)
-INITIALIZE_PASS_DEPENDENCY(RuntimeLibraryInfoWrapper)
-INITIALIZE_PASS_END(LibcallLoweringInfoWrapper, "libcall-lowering-info",
-                    "Library Function Lowering Analysis", false, true)
-
-char LibcallLoweringInfoWrapper::ID = 0;
-
-LibcallLoweringInfoWrapper::LibcallLoweringInfoWrapper() : ImmutablePass(ID) {}
-
-bool LibcallLoweringInfoWrapper::doInitialization(Module &M) {
-  Result.init(&getAnalysis<RuntimeLibraryInfoWrapper>().getRTLCI(M));
-  return false;
-}
-
-void LibcallLoweringInfoWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
-  AU.addRequired<RuntimeLibraryInfoWrapper>();
-  AU.setPreservesAll();
-}
-
-void LibcallLoweringInfoWrapper::releaseMemory() { Result.clear(); }
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 97da9abab0b7b..382d84a2ef030 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -17,7 +17,6 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/ExpandVectorPredication.h"
-#include "llvm/CodeGen/LibcallLoweringInfo.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/TargetLowering.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
@@ -54,7 +53,6 @@ namespace {
 
 struct PreISelIntrinsicLowering {
   const TargetMachine *TM;
-  const LibcallLoweringModuleAnalysisResult &ModuleLibcalls;
   const function_ref<TargetTransformInfo &(Function &)> LookupTTI;
   const function_ref<TargetLibraryInfo &(Function &)> LookupTLI;
 
@@ -65,13 +63,11 @@ struct PreISelIntrinsicLowering {
 
   explicit PreISelIntrinsicLowering(
       const TargetMachine *TM_,
-      const LibcallLoweringModuleAnalysisResult &ModuleLibcalls_,
       function_ref<TargetTransformInfo &(Function &)> LookupTTI_,
       function_ref<TargetLibraryInfo &(Function &)> LookupTLI_,
       bool UseMemIntrinsicLibFunc_ = true)
-      : TM(TM_), ModuleLibcalls(ModuleLibcalls_), LookupTTI(LookupTTI_),
-        LookupTLI(LookupTLI_), UseMemIntrinsicLibFunc(UseMemIntrinsicLibFunc_) {
-  }
+      : TM(TM_), LookupTTI(LookupTTI_), LookupTLI(LookupTLI_),
+        UseMemIntrinsicLibFunc(UseMemIntrinsicLibFunc_) {}
 
   static bool shouldExpandMemIntrinsicWithSize(Value *Size,
                                                const TargetTransformInfo &TTI);
@@ -236,26 +232,21 @@ bool PreISelIntrinsicLowering::shouldExpandMemIntrinsicWithSize(
   return SizeVal > Threshold || Threshold == 0;
 }
 
-static bool
-canEmitLibcall(const LibcallLoweringModuleAnalysisResult &ModuleLowering,
-               const TargetMachine *TM, Function *F, RTLIB::Libcall LC) {
+static bool canEmitLibcall(const TargetMachine *TM, Function *F,
+                           RTLIB::Libcall LC) {
   // TODO: Should this consider the address space of the memcpy?
   if (!TM)
     return true;
-  const LibcallLoweringInfo &Lowering =
-      ModuleLowering.getLibcallLowering(*TM->getSubtargetImpl(*F));
-  return Lowering.getLibcallImpl(LC) != RTLIB::Unsupported;
+  const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getLibcallName(LC) != nullptr;
 }
 
-static bool
-canEmitMemcpy(const LibcallLoweringModuleAnalysisResult &ModuleLowering,
-              const TargetMachine *TM, Function *F) {
+static bool canEmitMemcpy(const TargetMachine *TM, Function *F) {
   // TODO: Should this consider the address space of the memcpy?
   if (!TM)
     return true;
-  const LibcallLoweringInfo &Lowering =
-      ModuleLowering.getLibcallLowering(*TM->getSubtargetImpl(*F));
-  return Lowering.getMemcpyImpl() != RTLIB::Unsupported;
+  const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getMemcpyImpl() != RTLIB::Unsupported;
 }
 
 // Return a value appropriate for use with the memset_pattern16 libcall, if
@@ -328,8 +319,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       Function *ParentFunc = Memcpy->getFunction();
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memcpy->getLength(), TTI)) {
-        if (UseMemIntrinsicLibFunc &&
-            canEmitMemcpy(ModuleLibcalls, TM, ParentFunc))
+        if (UseMemIntrinsicLibFunc && canEmitMemcpy(TM, ParentFunc))
           break;
 
         // TODO: For optsize, emit the loop into a separate function
@@ -361,7 +351,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memmove->getLength(), TTI)) {
         if (UseMemIntrinsicLibFunc &&
-            canEmitLibcall(ModuleLibcalls, TM, ParentFunc, RTLIB::MEMMOVE))
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMMOVE))
           break;
 
         if (expandMemMoveAsLoop(Memmove, TTI)) {
@@ -378,7 +368,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memset->getLength(), TTI)) {
         if (UseMemIntrinsicLibFunc &&
-            canEmitLibcall(ModuleLibcalls, TM, ParentFunc, RTLIB::MEMSET))
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMSET))
           break;
 
         expandMemSetAsLoop(Memset);
@@ -772,14 +762,10 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass {
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<TargetTransformInfoWrapperPass>();
     AU.addRequired<TargetLibraryInfoWrapperPass>();
-    AU.addRequired<LibcallLoweringInfoWrapper>();
     AU.addRequired<TargetPassConfig>();
   }
 
   bool runOnModule(Module &M) override {
-    const LibcallLoweringModuleAnalysisResult &ModuleLibcalls =
-        getAnalysis<LibcallLoweringInfoWrapper>().getResult();
-
     auto LookupTTI = [this](Function &F) -> TargetTransformInfo & {
       return this->getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
     };
@@ -788,7 +774,7 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass {
     };
 
     const a...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-lto

Author: Alexey Bataev (alexey-bataev)

Changes

This reverts commit 04c81a9.

This patch causes massive perf regressions at all opt levels, from O0 to
O3. At O0 with the debug info it creates lots of spills/reloads. At
Higher opt level LoppVectorizer cannot vectorizer the expanded code,
becausde it is not aware of the non-aliasing of the pointers. It also
may increase register pressure.
The pass should include cost modelling, should emit hints for the
vectorizer. Without this, it should be disabled.


Patch is 49.92 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/171452.diff

37 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (-6)
  • (modified) llvm/include/llvm/Analysis/RuntimeLibcallInfo.h (+5-17)
  • (modified) llvm/include/llvm/CodeGen/LibcallLoweringInfo.h (-68)
  • (modified) llvm/include/llvm/InitializePasses.h (-1)
  • (modified) llvm/lib/Analysis/RuntimeLibcallInfo.cpp (-16)
  • (modified) llvm/lib/CodeGen/CodeGen.cpp (-1)
  • (modified) llvm/lib/CodeGen/ExpandFp.cpp (+8-32)
  • (modified) llvm/lib/CodeGen/LibcallLoweringInfo.cpp (-42)
  • (modified) llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp (+17-36)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (-6)
  • (modified) llvm/lib/Passes/PassRegistry.def (-1)
  • (modified) llvm/test/CodeGen/AArch64/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/AArch64/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/AMDGPU/llc-pipeline.ll (-10)
  • (modified) llvm/test/CodeGen/LoongArch/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/LoongArch/opt-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/PowerPC/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/PowerPC/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/RISCV/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/RISCV/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/SPIRV/llc-pipeline.ll (-4)
  • (modified) llvm/test/CodeGen/X86/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/X86/opt-pipeline.ll (-2)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/frem-inf.ll (+2-2)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/frem.ll (+1-1)
  • (removed) llvm/test/Transforms/ExpandFp/AMDGPU/missing-analysis.ll (-6)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/pass-parameters.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-fptosi129.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-fptoui129.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-si129tofp.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-ui129tofp.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-optnone.ll (+1-1)
  • (modified) llvm/tools/llc/NewPMDriver.cpp (-12)
  • (modified) llvm/tools/llc/llc.cpp (-5)
  • (modified) llvm/tools/opt/NewPMDriver.cpp (+6-17)
  • (modified) llvm/tools/opt/NewPMDriver.h (+7-3)
  • (modified) llvm/tools/opt/optdriver.cpp (+7-12)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 126005a5d93c2..df716e5bce23f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -19,7 +19,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Analysis/GlobalsModRef.h"
-#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -656,11 +655,6 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
       llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
 
-  const llvm::TargetOptions &Options = TM->Options;
-  CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
-      TargetTriple, Options.ExceptionModel, Options.FloatABIType,
-      Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
-
   // Normal mode, emit a .s or .o file by running the code generator. Note,
   // this also adds codegenerator level optimization passes.
   CodeGenFileType CGFT = getCodeGenFileType(Action);
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 609568ebc21a8..79737795e8291 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -22,12 +22,7 @@ class LLVM_ABI RuntimeLibraryAnalysis
   RuntimeLibraryAnalysis() = default;
   RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&BaselineInfoImpl)
       : LibcallsInfo(std::move(BaselineInfoImpl)) {}
-  RuntimeLibraryAnalysis(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  explicit RuntimeLibraryAnalysis(const Triple &T) : LibcallsInfo(T) {}
 
   RTLIB::RuntimeLibcallsInfo run(const Module &M, ModuleAnalysisManager &);
 
@@ -45,19 +40,12 @@ class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
 public:
   static char ID;
   RuntimeLibraryInfoWrapper();
-  RuntimeLibraryInfoWrapper(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  explicit RuntimeLibraryInfoWrapper(const Triple &T);
+  explicit RuntimeLibraryInfoWrapper(const RTLIB::RuntimeLibcallsInfo &RTLCI);
 
   const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) {
-    if (!RTLCI) {
-      ModuleAnalysisManager DummyMAM;
-      RTLCI = RTLA.run(M, DummyMAM);
-    }
-
+    ModuleAnalysisManager DummyMAM;
+    RTLCI = RTLA.run(M, DummyMAM);
     return *RTLCI;
   }
 
diff --git a/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h b/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
index 3e0137710e8eb..8624fd2403a12 100644
--- a/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
+++ b/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
@@ -9,16 +9,12 @@
 #ifndef LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
 #define LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
 
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/IR/RuntimeLibcalls.h"
-#include "llvm/Pass.h"
 
 namespace llvm {
 
 class TargetSubtargetInfo;
-class TargetMachine;
 
-/// Tracks which library functions to use for a particular subtarget.
 class LibcallLoweringInfo {
 private:
   const RTLIB::RuntimeLibcallsInfo &RTLCI;
@@ -77,70 +73,6 @@ class LibcallLoweringInfo {
   }
 };
 
-/// Record a mapping from subtarget to LibcallLoweringInfo.
-class LibcallLoweringModuleAnalysisResult {
-private:
-  using LibcallLoweringMap =
-      DenseMap<const TargetSubtargetInfo *, LibcallLoweringInfo>;
-  mutable LibcallLoweringMap LoweringMap;
-  const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr;
-
-public:
-  LibcallLoweringModuleAnalysisResult() = default;
-  LibcallLoweringModuleAnalysisResult(RTLIB::RuntimeLibcallsInfo &RTLCI)
-      : RTLCI(&RTLCI) {}
-
-  void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; }
-
-  void clear() {
-    RTLCI = nullptr;
-    LoweringMap.clear();
-  }
-
-  LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &,
-                           ModuleAnalysisManager::Invalidator &);
-
-  const LibcallLoweringInfo &
-  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
-    return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second;
-  }
-};
-
-class LibcallLoweringModuleAnalysis
-    : public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> {
-private:
-  friend AnalysisInfoMixin<LibcallLoweringModuleAnalysis>;
-  static AnalysisKey Key;
-
-  LibcallLoweringModuleAnalysisResult LibcallLoweringMap;
-
-public:
-  using Result = LibcallLoweringModuleAnalysisResult;
-
-  LLVM_ABI Result run(Module &M, ModuleAnalysisManager &);
-};
-
-class LLVM_ABI LibcallLoweringInfoWrapper : public ImmutablePass {
-  LibcallLoweringModuleAnalysisResult Result;
-
-public:
-  static char ID;
-  LibcallLoweringInfoWrapper();
-
-  const LibcallLoweringInfo &
-  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
-    return Result.getLibcallLowering(Subtarget);
-  }
-
-  const LibcallLoweringModuleAnalysisResult &getResult() const {
-    return Result;
-  }
-
-  bool doInitialization(Module &M) override;
-  void getAnalysisUsage(AnalysisUsage &AU) const override;
-  void releaseMemory() override;
-};
-
 } // end namespace llvm
 
 #endif // LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index a5491e68bbe52..18732caf78966 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -134,7 +134,6 @@ LLVM_ABI void initializeGlobalMergeFuncPassWrapperPass(PassRegistry &);
 LLVM_ABI void initializeGlobalMergePass(PassRegistry &);
 LLVM_ABI void initializeGlobalsAAWrapperPassPass(PassRegistry &);
 LLVM_ABI void initializeHardwareLoopsLegacyPass(PassRegistry &);
-LLVM_ABI void initializeLibcallLoweringInfoWrapperPass(PassRegistry &);
 LLVM_ABI void initializeMIRProfileLoaderPassPass(PassRegistry &);
 LLVM_ABI void initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &);
 LLVM_ABI void initializeIRTranslatorPass(PassRegistry &);
diff --git a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
index 1c5a1cc75b7bd..9ea789a4ee45a 100644
--- a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
+++ b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
@@ -13,15 +13,6 @@ using namespace llvm;
 
 AnalysisKey RuntimeLibraryAnalysis::Key;
 
-RuntimeLibraryAnalysis::RuntimeLibraryAnalysis(const Triple &TT,
-                                               ExceptionHandling ExceptionModel,
-                                               FloatABI::ABIType FloatABI,
-                                               EABI EABIVersion,
-                                               StringRef ABIName,
-                                               VectorLibrary VecLib)
-    : LibcallsInfo(std::in_place, TT, ExceptionModel, FloatABI, EABIVersion,
-                   ABIName, VecLib) {}
-
 RTLIB::RuntimeLibcallsInfo
 RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
   if (!LibcallsInfo)
@@ -35,13 +26,6 @@ INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
 RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper()
     : ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {}
 
-RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(
-    const Triple &TT, ExceptionHandling ExceptionModel,
-    FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName,
-    VectorLibrary VecLib)
-    : ImmutablePass(ID), RTLCI(std::in_place, TT, ExceptionModel, FloatABI,
-                               EABIVersion, ABIName, VecLib) {}
-
 char RuntimeLibraryInfoWrapper::ID = 0;
 
 ModulePass *llvm::createRuntimeLibraryInfoWrapperPass() {
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index fe293c63fa762..9795a0b707fd3 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -57,7 +57,6 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeInterleavedLoadCombinePass(Registry);
   initializeInterleavedAccessPass(Registry);
   initializeJMCInstrumenterPass(Registry);
-  initializeLibcallLoweringInfoWrapperPass(Registry);
   initializeLiveDebugValuesLegacyPass(Registry);
   initializeLiveDebugVariablesWrapperLegacyPass(Registry);
   initializeLiveIntervalsWrapperPassPass(Registry);
diff --git a/llvm/lib/CodeGen/ExpandFp.cpp b/llvm/lib/CodeGen/ExpandFp.cpp
index 13ed4846d2bf7..f44eb227133ae 100644
--- a/llvm/lib/CodeGen/ExpandFp.cpp
+++ b/llvm/lib/CodeGen/ExpandFp.cpp
@@ -975,12 +975,11 @@ static RTLIB::Libcall fremToLibcall(Type *Ty) {
 /* Return true if, according to \p LibInfo, the target either directly
    supports the frem instruction for the \p Ty, has a custom lowering,
    or uses a libcall. */
-static bool targetSupportsFrem(const TargetLowering &TLI,
-                               const LibcallLoweringInfo &Libcalls, Type *Ty) {
+static bool targetSupportsFrem(const TargetLowering &TLI, Type *Ty) {
   if (!TLI.isOperationExpand(ISD::FREM, EVT::getEVT(Ty)))
     return true;
 
-  return Libcalls.getLibcallName(fremToLibcall(Ty->getScalarType()));
+  return TLI.getLibcallName(fremToLibcall(Ty->getScalarType()));
 }
 
 static void addToWorklist(Instruction &I,
@@ -992,7 +991,7 @@ static void addToWorklist(Instruction &I,
 }
 
 static bool runImpl(Function &F, const TargetLowering &TLI,
-                    const LibcallLoweringInfo &Libcalls, AssumptionCache *AC) {
+                    AssumptionCache *AC) {
   SmallVector<Instruction *, 4> Worklist;
 
   unsigned MaxLegalFpConvertBitWidth =
@@ -1011,7 +1010,7 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
 
     switch (I.getOpcode()) {
     case Instruction::FRem:
-      return !targetSupportsFrem(TLI, Libcalls, Ty) &&
+      return !targetSupportsFrem(TLI, Ty) &&
              FRemExpander::canExpandType(Ty->getScalarType());
 
     case Instruction::FPToUI:
@@ -1091,27 +1090,20 @@ class ExpandFpLegacyPass : public FunctionPass {
 
   bool runOnFunction(Function &F) override {
     auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
-    const TargetSubtargetInfo *Subtarget = TM->getSubtargetImpl(F);
-    auto *TLI = Subtarget->getTargetLowering();
+    auto *TLI = TM->getSubtargetImpl(F)->getTargetLowering();
     AssumptionCache *AC = nullptr;
 
-    const LibcallLoweringInfo &Libcalls =
-        getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering(
-            *Subtarget);
-
     if (OptLevel != CodeGenOptLevel::None && !F.hasOptNone())
       AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
-    return runImpl(F, *TLI, Libcalls, AC);
+    return runImpl(F, *TLI, AC);
   }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
-    AU.addRequired<LibcallLoweringInfoWrapper>();
     AU.addRequired<TargetPassConfig>();
     if (OptLevel != CodeGenOptLevel::None)
       AU.addRequired<AssumptionCacheTracker>();
     AU.addPreserved<AAResultsWrapperPass>();
     AU.addPreserved<GlobalsAAWrapperPass>();
-    AU.addRequired<LibcallLoweringInfoWrapper>();
   }
 };
 } // namespace
@@ -1134,29 +1126,13 @@ PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) {
   AssumptionCache *AC = nullptr;
   if (OptLevel != CodeGenOptLevel::None)
     AC = &FAM.getResult<AssumptionAnalysis>(F);
-
-  auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
-
-  const LibcallLoweringModuleAnalysisResult *LibcallLowering =
-      MAMProxy.getCachedResult<LibcallLoweringModuleAnalysis>(*F.getParent());
-
-  if (!LibcallLowering) {
-    F.getContext().emitError("'" + LibcallLoweringModuleAnalysis::name() +
-                             "' analysis required");
-    return PreservedAnalyses::all();
-  }
-
-  const LibcallLoweringInfo &Libcalls =
-      LibcallLowering->getLibcallLowering(*STI);
-
-  return runImpl(F, TLI, Libcalls, AC) ? PreservedAnalyses::none()
-                                       : PreservedAnalyses::all();
+  return runImpl(F, TLI, AC) ? PreservedAnalyses::none()
+                             : PreservedAnalyses::all();
 }
 
 char ExpandFpLegacyPass::ID = 0;
 INITIALIZE_PASS_BEGIN(ExpandFpLegacyPass, "expand-fp",
                       "Expand certain fp instructions", false, false)
-INITIALIZE_PASS_DEPENDENCY(LibcallLoweringInfoWrapper)
 INITIALIZE_PASS_END(ExpandFpLegacyPass, "expand-fp", "Expand fp", false, false)
 
 FunctionPass *llvm::createExpandFpPass(CodeGenOptLevel OptLevel) {
diff --git a/llvm/lib/CodeGen/LibcallLoweringInfo.cpp b/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
index 0d54fac2422e2..6f3607e8db824 100644
--- a/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
@@ -7,10 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/LibcallLoweringInfo.h"
-#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
-#include "llvm/InitializePasses.h"
-#include "llvm/Target/TargetMachine.h"
 
 using namespace llvm;
 
@@ -31,42 +28,3 @@ LibcallLoweringInfo::LibcallLoweringInfo(
 
   Subtarget.initLibcallLoweringInfo(*this);
 }
-
-AnalysisKey LibcallLoweringModuleAnalysis::Key;
-
-bool LibcallLoweringModuleAnalysisResult::invalidate(
-    Module &, const PreservedAnalyses &PA,
-    ModuleAnalysisManager::Invalidator &) {
-  // Passes that change the runtime libcall set must explicitly invalidate this
-  // pass.
-  auto PAC = PA.getChecker<LibcallLoweringModuleAnalysis>();
-  return !PAC.preservedWhenStateless();
-}
-
-LibcallLoweringModuleAnalysisResult
-LibcallLoweringModuleAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
-  LibcallLoweringMap.init(&MAM.getResult<RuntimeLibraryAnalysis>(M));
-  return LibcallLoweringMap;
-}
-
-INITIALIZE_PASS_BEGIN(LibcallLoweringInfoWrapper, "libcall-lowering-info",
-                      "Library Function Lowering Analysis", false, true)
-INITIALIZE_PASS_DEPENDENCY(RuntimeLibraryInfoWrapper)
-INITIALIZE_PASS_END(LibcallLoweringInfoWrapper, "libcall-lowering-info",
-                    "Library Function Lowering Analysis", false, true)
-
-char LibcallLoweringInfoWrapper::ID = 0;
-
-LibcallLoweringInfoWrapper::LibcallLoweringInfoWrapper() : ImmutablePass(ID) {}
-
-bool LibcallLoweringInfoWrapper::doInitialization(Module &M) {
-  Result.init(&getAnalysis<RuntimeLibraryInfoWrapper>().getRTLCI(M));
-  return false;
-}
-
-void LibcallLoweringInfoWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
-  AU.addRequired<RuntimeLibraryInfoWrapper>();
-  AU.setPreservesAll();
-}
-
-void LibcallLoweringInfoWrapper::releaseMemory() { Result.clear(); }
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 97da9abab0b7b..382d84a2ef030 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -17,7 +17,6 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/ExpandVectorPredication.h"
-#include "llvm/CodeGen/LibcallLoweringInfo.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/TargetLowering.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
@@ -54,7 +53,6 @@ namespace {
 
 struct PreISelIntrinsicLowering {
   const TargetMachine *TM;
-  const LibcallLoweringModuleAnalysisResult &ModuleLibcalls;
   const function_ref<TargetTransformInfo &(Function &)> LookupTTI;
   const function_ref<TargetLibraryInfo &(Function &)> LookupTLI;
 
@@ -65,13 +63,11 @@ struct PreISelIntrinsicLowering {
 
   explicit PreISelIntrinsicLowering(
       const TargetMachine *TM_,
-      const LibcallLoweringModuleAnalysisResult &ModuleLibcalls_,
       function_ref<TargetTransformInfo &(Function &)> LookupTTI_,
       function_ref<TargetLibraryInfo &(Function &)> LookupTLI_,
       bool UseMemIntrinsicLibFunc_ = true)
-      : TM(TM_), ModuleLibcalls(ModuleLibcalls_), LookupTTI(LookupTTI_),
-        LookupTLI(LookupTLI_), UseMemIntrinsicLibFunc(UseMemIntrinsicLibFunc_) {
-  }
+      : TM(TM_), LookupTTI(LookupTTI_), LookupTLI(LookupTLI_),
+        UseMemIntrinsicLibFunc(UseMemIntrinsicLibFunc_) {}
 
   static bool shouldExpandMemIntrinsicWithSize(Value *Size,
                                                const TargetTransformInfo &TTI);
@@ -236,26 +232,21 @@ bool PreISelIntrinsicLowering::shouldExpandMemIntrinsicWithSize(
   return SizeVal > Threshold || Threshold == 0;
 }
 
-static bool
-canEmitLibcall(const LibcallLoweringModuleAnalysisResult &ModuleLowering,
-               const TargetMachine *TM, Function *F, RTLIB::Libcall LC) {
+static bool canEmitLibcall(const TargetMachine *TM, Function *F,
+                           RTLIB::Libcall LC) {
   // TODO: Should this consider the address space of the memcpy?
   if (!TM)
     return true;
-  const LibcallLoweringInfo &Lowering =
-      ModuleLowering.getLibcallLowering(*TM->getSubtargetImpl(*F));
-  return Lowering.getLibcallImpl(LC) != RTLIB::Unsupported;
+  const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getLibcallName(LC) != nullptr;
 }
 
-static bool
-canEmitMemcpy(const LibcallLoweringModuleAnalysisResult &ModuleLowering,
-              const TargetMachine *TM, Function *F) {
+static bool canEmitMemcpy(const TargetMachine *TM, Function *F) {
   // TODO: Should this consider the address space of the memcpy?
   if (!TM)
     return true;
-  const LibcallLoweringInfo &Lowering =
-      ModuleLowering.getLibcallLowering(*TM->getSubtargetImpl(*F));
-  return Lowering.getMemcpyImpl() != RTLIB::Unsupported;
+  const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getMemcpyImpl() != RTLIB::Unsupported;
 }
 
 // Return a value appropriate for use with the memset_pattern16 libcall, if
@@ -328,8 +319,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       Function *ParentFunc = Memcpy->getFunction();
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memcpy->getLength(), TTI)) {
-        if (UseMemIntrinsicLibFunc &&
-            canEmitMemcpy(ModuleLibcalls, TM, ParentFunc))
+        if (UseMemIntrinsicLibFunc && canEmitMemcpy(TM, ParentFunc))
           break;
 
         // TODO: For optsize, emit the loop into a separate function
@@ -361,7 +351,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memmove->getLength(), TTI)) {
         if (UseMemIntrinsicLibFunc &&
-            canEmitLibcall(ModuleLibcalls, TM, ParentFunc, RTLIB::MEMMOVE))
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMMOVE))
           break;
 
         if (expandMemMoveAsLoop(Memmove, TTI)) {
@@ -378,7 +368,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memset->getLength(), TTI)) {
         if (UseMemIntrinsicLibFunc &&
-            canEmitLibcall(ModuleLibcalls, TM, ParentFunc, RTLIB::MEMSET))
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMSET))
           break;
 
         expandMemSetAsLoop(Memset);
@@ -772,14 +762,10 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass {
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<TargetTransformInfoWrapperPass>();
     AU.addRequired<TargetLibraryInfoWrapperPass>();
-    AU.addRequired<LibcallLoweringInfoWrapper>();
     AU.addRequired<TargetPassConfig>();
   }
 
   bool runOnModule(Module &M) override {
-    const LibcallLoweringModuleAnalysisResult &ModuleLibcalls =
-        getAnalysis<LibcallLoweringInfoWrapper>().getResult();
-
     auto LookupTTI = [this](Function &F) -> TargetTransformInfo & {
       return this->getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
     };
@@ -788,7 +774,7 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass {
     };
 
     const a...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-backend-loongarch

Author: Alexey Bataev (alexey-bataev)

Changes

This reverts commit 04c81a9.

This patch causes massive perf regressions at all opt levels, from O0 to
O3. At O0 with the debug info it creates lots of spills/reloads. At
Higher opt level LoppVectorizer cannot vectorizer the expanded code,
becausde it is not aware of the non-aliasing of the pointers. It also
may increase register pressure.
The pass should include cost modelling, should emit hints for the
vectorizer. Without this, it should be disabled.


Patch is 49.92 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/171452.diff

37 Files Affected:

  • (modified) clang/lib/CodeGen/BackendUtil.cpp (-6)
  • (modified) llvm/include/llvm/Analysis/RuntimeLibcallInfo.h (+5-17)
  • (modified) llvm/include/llvm/CodeGen/LibcallLoweringInfo.h (-68)
  • (modified) llvm/include/llvm/InitializePasses.h (-1)
  • (modified) llvm/lib/Analysis/RuntimeLibcallInfo.cpp (-16)
  • (modified) llvm/lib/CodeGen/CodeGen.cpp (-1)
  • (modified) llvm/lib/CodeGen/ExpandFp.cpp (+8-32)
  • (modified) llvm/lib/CodeGen/LibcallLoweringInfo.cpp (-42)
  • (modified) llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp (+17-36)
  • (modified) llvm/lib/LTO/LTOBackend.cpp (-6)
  • (modified) llvm/lib/Passes/PassRegistry.def (-1)
  • (modified) llvm/test/CodeGen/AArch64/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/AArch64/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/AMDGPU/llc-pipeline.ll (-10)
  • (modified) llvm/test/CodeGen/LoongArch/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/LoongArch/opt-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/PowerPC/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/PowerPC/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/RISCV/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/RISCV/O3-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/SPIRV/llc-pipeline.ll (-4)
  • (modified) llvm/test/CodeGen/X86/O0-pipeline.ll (-2)
  • (modified) llvm/test/CodeGen/X86/opt-pipeline.ll (-2)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/frem-inf.ll (+2-2)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/frem.ll (+1-1)
  • (removed) llvm/test/Transforms/ExpandFp/AMDGPU/missing-analysis.ll (-6)
  • (modified) llvm/test/Transforms/ExpandFp/AMDGPU/pass-parameters.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-fptosi129.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-fptoui129.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-si129tofp.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-convert-ui129tofp.ll (+1-1)
  • (modified) llvm/test/Transforms/ExpandLargeFpConvert/X86/expand-large-fp-optnone.ll (+1-1)
  • (modified) llvm/tools/llc/NewPMDriver.cpp (-12)
  • (modified) llvm/tools/llc/llc.cpp (-5)
  • (modified) llvm/tools/opt/NewPMDriver.cpp (+6-17)
  • (modified) llvm/tools/opt/NewPMDriver.h (+7-3)
  • (modified) llvm/tools/opt/optdriver.cpp (+7-12)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 126005a5d93c2..df716e5bce23f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -19,7 +19,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Analysis/GlobalsModRef.h"
-#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -656,11 +655,6 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
       llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
   CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII));
 
-  const llvm::TargetOptions &Options = TM->Options;
-  CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
-      TargetTriple, Options.ExceptionModel, Options.FloatABIType,
-      Options.EABIVersion, Options.MCOptions.ABIName, Options.VecLib));
-
   // Normal mode, emit a .s or .o file by running the code generator. Note,
   // this also adds codegenerator level optimization passes.
   CodeGenFileType CGFT = getCodeGenFileType(Action);
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 609568ebc21a8..79737795e8291 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -22,12 +22,7 @@ class LLVM_ABI RuntimeLibraryAnalysis
   RuntimeLibraryAnalysis() = default;
   RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&BaselineInfoImpl)
       : LibcallsInfo(std::move(BaselineInfoImpl)) {}
-  RuntimeLibraryAnalysis(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  explicit RuntimeLibraryAnalysis(const Triple &T) : LibcallsInfo(T) {}
 
   RTLIB::RuntimeLibcallsInfo run(const Module &M, ModuleAnalysisManager &);
 
@@ -45,19 +40,12 @@ class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
 public:
   static char ID;
   RuntimeLibraryInfoWrapper();
-  RuntimeLibraryInfoWrapper(
-      const Triple &TT,
-      ExceptionHandling ExceptionModel = ExceptionHandling::None,
-      FloatABI::ABIType FloatABI = FloatABI::Default,
-      EABI EABIVersion = EABI::Default, StringRef ABIName = "",
-      VectorLibrary VecLib = VectorLibrary::NoLibrary);
+  explicit RuntimeLibraryInfoWrapper(const Triple &T);
+  explicit RuntimeLibraryInfoWrapper(const RTLIB::RuntimeLibcallsInfo &RTLCI);
 
   const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) {
-    if (!RTLCI) {
-      ModuleAnalysisManager DummyMAM;
-      RTLCI = RTLA.run(M, DummyMAM);
-    }
-
+    ModuleAnalysisManager DummyMAM;
+    RTLCI = RTLA.run(M, DummyMAM);
     return *RTLCI;
   }
 
diff --git a/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h b/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
index 3e0137710e8eb..8624fd2403a12 100644
--- a/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
+++ b/llvm/include/llvm/CodeGen/LibcallLoweringInfo.h
@@ -9,16 +9,12 @@
 #ifndef LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
 #define LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
 
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/IR/RuntimeLibcalls.h"
-#include "llvm/Pass.h"
 
 namespace llvm {
 
 class TargetSubtargetInfo;
-class TargetMachine;
 
-/// Tracks which library functions to use for a particular subtarget.
 class LibcallLoweringInfo {
 private:
   const RTLIB::RuntimeLibcallsInfo &RTLCI;
@@ -77,70 +73,6 @@ class LibcallLoweringInfo {
   }
 };
 
-/// Record a mapping from subtarget to LibcallLoweringInfo.
-class LibcallLoweringModuleAnalysisResult {
-private:
-  using LibcallLoweringMap =
-      DenseMap<const TargetSubtargetInfo *, LibcallLoweringInfo>;
-  mutable LibcallLoweringMap LoweringMap;
-  const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr;
-
-public:
-  LibcallLoweringModuleAnalysisResult() = default;
-  LibcallLoweringModuleAnalysisResult(RTLIB::RuntimeLibcallsInfo &RTLCI)
-      : RTLCI(&RTLCI) {}
-
-  void init(const RTLIB::RuntimeLibcallsInfo *RT) { RTLCI = RT; }
-
-  void clear() {
-    RTLCI = nullptr;
-    LoweringMap.clear();
-  }
-
-  LLVM_ABI bool invalidate(Module &, const PreservedAnalyses &,
-                           ModuleAnalysisManager::Invalidator &);
-
-  const LibcallLoweringInfo &
-  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
-    return LoweringMap.try_emplace(&Subtarget, *RTLCI, Subtarget).first->second;
-  }
-};
-
-class LibcallLoweringModuleAnalysis
-    : public AnalysisInfoMixin<LibcallLoweringModuleAnalysis> {
-private:
-  friend AnalysisInfoMixin<LibcallLoweringModuleAnalysis>;
-  static AnalysisKey Key;
-
-  LibcallLoweringModuleAnalysisResult LibcallLoweringMap;
-
-public:
-  using Result = LibcallLoweringModuleAnalysisResult;
-
-  LLVM_ABI Result run(Module &M, ModuleAnalysisManager &);
-};
-
-class LLVM_ABI LibcallLoweringInfoWrapper : public ImmutablePass {
-  LibcallLoweringModuleAnalysisResult Result;
-
-public:
-  static char ID;
-  LibcallLoweringInfoWrapper();
-
-  const LibcallLoweringInfo &
-  getLibcallLowering(const TargetSubtargetInfo &Subtarget) const {
-    return Result.getLibcallLowering(Subtarget);
-  }
-
-  const LibcallLoweringModuleAnalysisResult &getResult() const {
-    return Result;
-  }
-
-  bool doInitialization(Module &M) override;
-  void getAnalysisUsage(AnalysisUsage &AU) const override;
-  void releaseMemory() override;
-};
-
 } // end namespace llvm
 
 #endif // LLVM_CODEGEN_LIBCALLLOWERINGINFO_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index a5491e68bbe52..18732caf78966 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -134,7 +134,6 @@ LLVM_ABI void initializeGlobalMergeFuncPassWrapperPass(PassRegistry &);
 LLVM_ABI void initializeGlobalMergePass(PassRegistry &);
 LLVM_ABI void initializeGlobalsAAWrapperPassPass(PassRegistry &);
 LLVM_ABI void initializeHardwareLoopsLegacyPass(PassRegistry &);
-LLVM_ABI void initializeLibcallLoweringInfoWrapperPass(PassRegistry &);
 LLVM_ABI void initializeMIRProfileLoaderPassPass(PassRegistry &);
 LLVM_ABI void initializeIRSimilarityIdentifierWrapperPassPass(PassRegistry &);
 LLVM_ABI void initializeIRTranslatorPass(PassRegistry &);
diff --git a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
index 1c5a1cc75b7bd..9ea789a4ee45a 100644
--- a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
+++ b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
@@ -13,15 +13,6 @@ using namespace llvm;
 
 AnalysisKey RuntimeLibraryAnalysis::Key;
 
-RuntimeLibraryAnalysis::RuntimeLibraryAnalysis(const Triple &TT,
-                                               ExceptionHandling ExceptionModel,
-                                               FloatABI::ABIType FloatABI,
-                                               EABI EABIVersion,
-                                               StringRef ABIName,
-                                               VectorLibrary VecLib)
-    : LibcallsInfo(std::in_place, TT, ExceptionModel, FloatABI, EABIVersion,
-                   ABIName, VecLib) {}
-
 RTLIB::RuntimeLibcallsInfo
 RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
   if (!LibcallsInfo)
@@ -35,13 +26,6 @@ INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
 RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper()
     : ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {}
 
-RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(
-    const Triple &TT, ExceptionHandling ExceptionModel,
-    FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName,
-    VectorLibrary VecLib)
-    : ImmutablePass(ID), RTLCI(std::in_place, TT, ExceptionModel, FloatABI,
-                               EABIVersion, ABIName, VecLib) {}
-
 char RuntimeLibraryInfoWrapper::ID = 0;
 
 ModulePass *llvm::createRuntimeLibraryInfoWrapperPass() {
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index fe293c63fa762..9795a0b707fd3 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -57,7 +57,6 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeInterleavedLoadCombinePass(Registry);
   initializeInterleavedAccessPass(Registry);
   initializeJMCInstrumenterPass(Registry);
-  initializeLibcallLoweringInfoWrapperPass(Registry);
   initializeLiveDebugValuesLegacyPass(Registry);
   initializeLiveDebugVariablesWrapperLegacyPass(Registry);
   initializeLiveIntervalsWrapperPassPass(Registry);
diff --git a/llvm/lib/CodeGen/ExpandFp.cpp b/llvm/lib/CodeGen/ExpandFp.cpp
index 13ed4846d2bf7..f44eb227133ae 100644
--- a/llvm/lib/CodeGen/ExpandFp.cpp
+++ b/llvm/lib/CodeGen/ExpandFp.cpp
@@ -975,12 +975,11 @@ static RTLIB::Libcall fremToLibcall(Type *Ty) {
 /* Return true if, according to \p LibInfo, the target either directly
    supports the frem instruction for the \p Ty, has a custom lowering,
    or uses a libcall. */
-static bool targetSupportsFrem(const TargetLowering &TLI,
-                               const LibcallLoweringInfo &Libcalls, Type *Ty) {
+static bool targetSupportsFrem(const TargetLowering &TLI, Type *Ty) {
   if (!TLI.isOperationExpand(ISD::FREM, EVT::getEVT(Ty)))
     return true;
 
-  return Libcalls.getLibcallName(fremToLibcall(Ty->getScalarType()));
+  return TLI.getLibcallName(fremToLibcall(Ty->getScalarType()));
 }
 
 static void addToWorklist(Instruction &I,
@@ -992,7 +991,7 @@ static void addToWorklist(Instruction &I,
 }
 
 static bool runImpl(Function &F, const TargetLowering &TLI,
-                    const LibcallLoweringInfo &Libcalls, AssumptionCache *AC) {
+                    AssumptionCache *AC) {
   SmallVector<Instruction *, 4> Worklist;
 
   unsigned MaxLegalFpConvertBitWidth =
@@ -1011,7 +1010,7 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
 
     switch (I.getOpcode()) {
     case Instruction::FRem:
-      return !targetSupportsFrem(TLI, Libcalls, Ty) &&
+      return !targetSupportsFrem(TLI, Ty) &&
              FRemExpander::canExpandType(Ty->getScalarType());
 
     case Instruction::FPToUI:
@@ -1091,27 +1090,20 @@ class ExpandFpLegacyPass : public FunctionPass {
 
   bool runOnFunction(Function &F) override {
     auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
-    const TargetSubtargetInfo *Subtarget = TM->getSubtargetImpl(F);
-    auto *TLI = Subtarget->getTargetLowering();
+    auto *TLI = TM->getSubtargetImpl(F)->getTargetLowering();
     AssumptionCache *AC = nullptr;
 
-    const LibcallLoweringInfo &Libcalls =
-        getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering(
-            *Subtarget);
-
     if (OptLevel != CodeGenOptLevel::None && !F.hasOptNone())
       AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
-    return runImpl(F, *TLI, Libcalls, AC);
+    return runImpl(F, *TLI, AC);
   }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
-    AU.addRequired<LibcallLoweringInfoWrapper>();
     AU.addRequired<TargetPassConfig>();
     if (OptLevel != CodeGenOptLevel::None)
       AU.addRequired<AssumptionCacheTracker>();
     AU.addPreserved<AAResultsWrapperPass>();
     AU.addPreserved<GlobalsAAWrapperPass>();
-    AU.addRequired<LibcallLoweringInfoWrapper>();
   }
 };
 } // namespace
@@ -1134,29 +1126,13 @@ PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) {
   AssumptionCache *AC = nullptr;
   if (OptLevel != CodeGenOptLevel::None)
     AC = &FAM.getResult<AssumptionAnalysis>(F);
-
-  auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
-
-  const LibcallLoweringModuleAnalysisResult *LibcallLowering =
-      MAMProxy.getCachedResult<LibcallLoweringModuleAnalysis>(*F.getParent());
-
-  if (!LibcallLowering) {
-    F.getContext().emitError("'" + LibcallLoweringModuleAnalysis::name() +
-                             "' analysis required");
-    return PreservedAnalyses::all();
-  }
-
-  const LibcallLoweringInfo &Libcalls =
-      LibcallLowering->getLibcallLowering(*STI);
-
-  return runImpl(F, TLI, Libcalls, AC) ? PreservedAnalyses::none()
-                                       : PreservedAnalyses::all();
+  return runImpl(F, TLI, AC) ? PreservedAnalyses::none()
+                             : PreservedAnalyses::all();
 }
 
 char ExpandFpLegacyPass::ID = 0;
 INITIALIZE_PASS_BEGIN(ExpandFpLegacyPass, "expand-fp",
                       "Expand certain fp instructions", false, false)
-INITIALIZE_PASS_DEPENDENCY(LibcallLoweringInfoWrapper)
 INITIALIZE_PASS_END(ExpandFpLegacyPass, "expand-fp", "Expand fp", false, false)
 
 FunctionPass *llvm::createExpandFpPass(CodeGenOptLevel OptLevel) {
diff --git a/llvm/lib/CodeGen/LibcallLoweringInfo.cpp b/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
index 0d54fac2422e2..6f3607e8db824 100644
--- a/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/LibcallLoweringInfo.cpp
@@ -7,10 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/LibcallLoweringInfo.h"
-#include "llvm/Analysis/RuntimeLibcallInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
-#include "llvm/InitializePasses.h"
-#include "llvm/Target/TargetMachine.h"
 
 using namespace llvm;
 
@@ -31,42 +28,3 @@ LibcallLoweringInfo::LibcallLoweringInfo(
 
   Subtarget.initLibcallLoweringInfo(*this);
 }
-
-AnalysisKey LibcallLoweringModuleAnalysis::Key;
-
-bool LibcallLoweringModuleAnalysisResult::invalidate(
-    Module &, const PreservedAnalyses &PA,
-    ModuleAnalysisManager::Invalidator &) {
-  // Passes that change the runtime libcall set must explicitly invalidate this
-  // pass.
-  auto PAC = PA.getChecker<LibcallLoweringModuleAnalysis>();
-  return !PAC.preservedWhenStateless();
-}
-
-LibcallLoweringModuleAnalysisResult
-LibcallLoweringModuleAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
-  LibcallLoweringMap.init(&MAM.getResult<RuntimeLibraryAnalysis>(M));
-  return LibcallLoweringMap;
-}
-
-INITIALIZE_PASS_BEGIN(LibcallLoweringInfoWrapper, "libcall-lowering-info",
-                      "Library Function Lowering Analysis", false, true)
-INITIALIZE_PASS_DEPENDENCY(RuntimeLibraryInfoWrapper)
-INITIALIZE_PASS_END(LibcallLoweringInfoWrapper, "libcall-lowering-info",
-                    "Library Function Lowering Analysis", false, true)
-
-char LibcallLoweringInfoWrapper::ID = 0;
-
-LibcallLoweringInfoWrapper::LibcallLoweringInfoWrapper() : ImmutablePass(ID) {}
-
-bool LibcallLoweringInfoWrapper::doInitialization(Module &M) {
-  Result.init(&getAnalysis<RuntimeLibraryInfoWrapper>().getRTLCI(M));
-  return false;
-}
-
-void LibcallLoweringInfoWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
-  AU.addRequired<RuntimeLibraryInfoWrapper>();
-  AU.setPreservesAll();
-}
-
-void LibcallLoweringInfoWrapper::releaseMemory() { Result.clear(); }
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 97da9abab0b7b..382d84a2ef030 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -17,7 +17,6 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/CodeGen/ExpandVectorPredication.h"
-#include "llvm/CodeGen/LibcallLoweringInfo.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/TargetLowering.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
@@ -54,7 +53,6 @@ namespace {
 
 struct PreISelIntrinsicLowering {
   const TargetMachine *TM;
-  const LibcallLoweringModuleAnalysisResult &ModuleLibcalls;
   const function_ref<TargetTransformInfo &(Function &)> LookupTTI;
   const function_ref<TargetLibraryInfo &(Function &)> LookupTLI;
 
@@ -65,13 +63,11 @@ struct PreISelIntrinsicLowering {
 
   explicit PreISelIntrinsicLowering(
       const TargetMachine *TM_,
-      const LibcallLoweringModuleAnalysisResult &ModuleLibcalls_,
       function_ref<TargetTransformInfo &(Function &)> LookupTTI_,
       function_ref<TargetLibraryInfo &(Function &)> LookupTLI_,
       bool UseMemIntrinsicLibFunc_ = true)
-      : TM(TM_), ModuleLibcalls(ModuleLibcalls_), LookupTTI(LookupTTI_),
-        LookupTLI(LookupTLI_), UseMemIntrinsicLibFunc(UseMemIntrinsicLibFunc_) {
-  }
+      : TM(TM_), LookupTTI(LookupTTI_), LookupTLI(LookupTLI_),
+        UseMemIntrinsicLibFunc(UseMemIntrinsicLibFunc_) {}
 
   static bool shouldExpandMemIntrinsicWithSize(Value *Size,
                                                const TargetTransformInfo &TTI);
@@ -236,26 +232,21 @@ bool PreISelIntrinsicLowering::shouldExpandMemIntrinsicWithSize(
   return SizeVal > Threshold || Threshold == 0;
 }
 
-static bool
-canEmitLibcall(const LibcallLoweringModuleAnalysisResult &ModuleLowering,
-               const TargetMachine *TM, Function *F, RTLIB::Libcall LC) {
+static bool canEmitLibcall(const TargetMachine *TM, Function *F,
+                           RTLIB::Libcall LC) {
   // TODO: Should this consider the address space of the memcpy?
   if (!TM)
     return true;
-  const LibcallLoweringInfo &Lowering =
-      ModuleLowering.getLibcallLowering(*TM->getSubtargetImpl(*F));
-  return Lowering.getLibcallImpl(LC) != RTLIB::Unsupported;
+  const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getLibcallName(LC) != nullptr;
 }
 
-static bool
-canEmitMemcpy(const LibcallLoweringModuleAnalysisResult &ModuleLowering,
-              const TargetMachine *TM, Function *F) {
+static bool canEmitMemcpy(const TargetMachine *TM, Function *F) {
   // TODO: Should this consider the address space of the memcpy?
   if (!TM)
     return true;
-  const LibcallLoweringInfo &Lowering =
-      ModuleLowering.getLibcallLowering(*TM->getSubtargetImpl(*F));
-  return Lowering.getMemcpyImpl() != RTLIB::Unsupported;
+  const TargetLowering *TLI = TM->getSubtargetImpl(*F)->getTargetLowering();
+  return TLI->getMemcpyImpl() != RTLIB::Unsupported;
 }
 
 // Return a value appropriate for use with the memset_pattern16 libcall, if
@@ -328,8 +319,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       Function *ParentFunc = Memcpy->getFunction();
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memcpy->getLength(), TTI)) {
-        if (UseMemIntrinsicLibFunc &&
-            canEmitMemcpy(ModuleLibcalls, TM, ParentFunc))
+        if (UseMemIntrinsicLibFunc && canEmitMemcpy(TM, ParentFunc))
           break;
 
         // TODO: For optsize, emit the loop into a separate function
@@ -361,7 +351,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memmove->getLength(), TTI)) {
         if (UseMemIntrinsicLibFunc &&
-            canEmitLibcall(ModuleLibcalls, TM, ParentFunc, RTLIB::MEMMOVE))
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMMOVE))
           break;
 
         if (expandMemMoveAsLoop(Memmove, TTI)) {
@@ -378,7 +368,7 @@ bool PreISelIntrinsicLowering::expandMemIntrinsicUses(
       const TargetTransformInfo &TTI = LookupTTI(*ParentFunc);
       if (shouldExpandMemIntrinsicWithSize(Memset->getLength(), TTI)) {
         if (UseMemIntrinsicLibFunc &&
-            canEmitLibcall(ModuleLibcalls, TM, ParentFunc, RTLIB::MEMSET))
+            canEmitLibcall(TM, ParentFunc, RTLIB::MEMSET))
           break;
 
         expandMemSetAsLoop(Memset);
@@ -772,14 +762,10 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass {
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<TargetTransformInfoWrapperPass>();
     AU.addRequired<TargetLibraryInfoWrapperPass>();
-    AU.addRequired<LibcallLoweringInfoWrapper>();
     AU.addRequired<TargetPassConfig>();
   }
 
   bool runOnModule(Module &M) override {
-    const LibcallLoweringModuleAnalysisResult &ModuleLibcalls =
-        getAnalysis<LibcallLoweringInfoWrapper>().getResult();
-
     auto LookupTTI = [this](Function &F) -> TargetTransformInfo & {
       return this->getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
     };
@@ -788,7 +774,7 @@ class PreISelIntrinsicLoweringLegacyPass : public ModulePass {
     };
 
     const a...
[truncated]

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unclear how this change leads to the effects that you describe. This change should essentially be NFC. You would only get impacts like you describe if suddenly intrinsics are getting lowered to loops or something rather than libcalls.

@alexey-bataev
Copy link
Member Author

Yep, we see that memcpy intrinsics started to be expanded into loops

@boomanaiden154
Copy link
Contributor

Yep, we see that memcpy intrinsics started to be expanded into loops

Are you using a custom pass pipeline? You will need something like halide/Halide#8892 or all of the libcalls will be marked as unsupported. If you have a custom target you might need to update RuntimeLibcalls.td so that memcpy and friends are enabled.

If this is with upstream clang/flang, this would be more concerning, but it does not seem like there are any regressions there. There are a decent amount of memory libcall lowering tests.

@alexey-bataev
Copy link
Member Author

Yep, we see that memcpy intrinsics started to be expanded into loops

Are you using a custom pass pipeline? You will need something like halide/Halide#8892 or all of the libcalls will be marked as unsupported. If you have a custom target you might need to update RuntimeLibcalls.td so that memcpy and friends are enabled.

If this is with upstream clang/flang, this would be more concerning, but it does not seem like there are any regressions there. There are a decent amount of memory libcall lowering tests.

It is flang, at least

@boomanaiden154
Copy link
Contributor

If we're going to revert this, it would be good to have a reproducer posted somewhere (eg a self contained fortran file that shows differing IR post PreISelLowering).

@alexey-bataev
Copy link
Member Author

Here is a small reproducer:

program memcpy_test
  implicit none
  integer, parameter :: n = 100
  real :: a(n), b(n)
  integer :: i

  ! Initialize array a
  do i = 1, n
    a(i) = real(i)
  end do

  ! Array assignment - this should generate memcpy
  b = a

  ! Use array b to prevent optimization
  print *, b(1), b(n)

end program memcpy_test

compile with flang -O2 memcpy_reproducer.f90 -mllvm -print-after-all on x86 target

 ; *** IR Dump After AnnotationRemarksPass on _QQmain ***
...
store float 9.700000e+01, ptr getelementptr inbounds nuw (i8, ptr @_QFEa, i64 384), align 16, !tbaa !4
store float 9.800000e+01, ptr getelementptr inbounds nuw (i8, ptr @_QFEa, i64 388), align 4, !tbaa !4
store float 9.900000e+01, ptr getelementptr inbounds nuw (i8, ptr @_QFEa, i64 392), align 8, !tbaa !4
store float 1.000000e+02, ptr getelementptr inbounds nuw (i8, ptr @_QFEa, i64 396), align 4, !tbaa !4
tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(400) @_QFEb, ptr noundef nonnull align 16 dereferenceable(400) @_QFEa, i64 400, i1 false), !tbaa !11
...

after Pre-ISel

*** IR Dump After Pre-ISel Intrinsic Lowering (pre-isel-intrinsic-lowering) ***

...
store float 9.700000e+01, ptr getelementptr inbounds nuw (i8, ptr @_QFEa, i64 384), align 16, !tbaa !4
store float 9.800000e+01, ptr getelementptr inbounds nuw (i8, ptr @_QFEa, i64 388), align 4, !tbaa !4
store float 9.900000e+01, ptr getelementptr inbounds nuw (i8, ptr @_QFEa, i64 392), align 8, !tbaa !4
store float 1.000000e+02, ptr getelementptr inbounds nuw (i8, ptr @_QFEa, i64 396), align 4, !tbaa !4
br label %static-memcpy-expansion-main-body

static-memcpy-expansion-main-body:                ; preds = %static-memcpy-expansion-main-body, %vector.ph
%loop-index = phi i64 [ 0, %vector.ph ], [ %3, %static-memcpy-expansion-main-body ]
%0 = getelementptr inbounds i8, ptr @_QFEa, i64 %loop-index
%1 = load i8, ptr %0, align 1
%2 = getelementptr inbounds i8, ptr @_QFEb, i64 %loop-index
store i8 %1, ptr %2, align 1
%3 = add i64 %loop-index, 1
%4 = icmp ult i64 %3, 400
br i1 %4, label %static-memcpy-expansion-main-body, label %static-memcpy-post-expansion

static-memcpy-post-expansion:
...

@alexey-bataev
Copy link
Member Author

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting for now seems fine to me. It wouldn't be a bad idea to wait for Matt to weigh in though.

My guess is the fix would be pretty simple, but reverting until we figure out what that is seems okay.

@arsenm
Copy link
Contributor

arsenm commented Dec 9, 2025

This is a pass pipeline issue. Everywhere manually adding TargetLibraryInfo to the pass pipeline needs to add RuntimeLibcallsInfo as well, until they are merged

@arsenm
Copy link
Contributor

arsenm commented Dec 9, 2025

So basically, don't revert. Fix whatever pipeline and add the appropriate test coverage

@arsenm
Copy link
Contributor

arsenm commented Dec 9, 2025

The pass should include cost modelling, should emit hints for the vectorizer.

No, this pass has nothing to do with cost modeling or optimization. This is a refactoring change to pull the library information out of TargetLibraryInfo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AArch64 backend:AMDGPU backend:loongarch backend:PowerPC backend:RISC-V backend:SPIR-V backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. llvm:analysis Includes value tracking, cost tables and constant folding llvm:codegen llvm:transforms LTO Link time optimization (regular/full LTO or ThinLTO)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants